--   DATEI:
--       ~hampptn/prokurs/examples/procedure_count.adb
--     PROJEKT:
--       Programmierkurs, example for using Ada_Tokenizer
--     ERZEUGT:
--       Thu Jan 18 14:39:29 CET 2001
--     VERSION:
--       $Id $
--     AUTOR:
--       Ralf Reissing
--     BESCHREIBUNG:
--       Determines the number of procedures in an Ada source file.
--       For each procedure its name and the number of the starting line
--       is displayed

with Ada_Tokenizer;
with Ada.Text_IO;
with Ada.Strings.Unbounded;

------------------------------------------------------------------------------
-- MAIN: procedure_count.adb
--
--   Copyright (c) 2000 Uni Stgt.
--   All rights reserved..
--
-- PROJECT: Programmierkurs, Blatt 6
-- VERSION: $Id$
-- CREATED: Tue Jan 23 14:23:57 CET 2001
-- AUTHOR:  Ralf Reissing
--
-- DESCRIPTION:
--   This program is a demo for the use of Ada_Tokenizer.
--   It determines the number of procedures in an Ada source file.
--   A list of the procedure names and their line numbers are printed.
-- PROGRAM USAGE:
--   Start program and enter Ada source file name when prompted
-- MODIFICATIONS:
------------------------------------------------------------------------------

procedure Procedure_Count is

  -- make the primitive operators for Token_Type visible
  use type Ada_Tokenizer.Token_Type;

  Filename: String (1..80);
  Procedure_Count: Natural := 0;
  Kind: Ada_Tokenizer.Token_Type;
  Value: Ada.Strings.Unbounded.Unbounded_String;
  Line: Positive;
  Last: Natural;
  OK: Boolean;
begin
  Ada.Text_IO.Put_Line ("This program determines the number of procedures"
    & " in an Ada source file.");
  Ada.Text_IO.Put ("Please enter file name: ");
  Ada.Text_IO.Get_Line (Filename, Last);
  Ada.Text_IO.Put_Line ("Opening " & Filename (1..Last) & " ...");
  Ada_Tokenizer.Open_Input (Filename (1..Last), OK);
  if OK then
    while Ada_Tokenizer.Token_Available loop
      Ada_Tokenizer.Get_Token (Kind, Value, Line);
      if Kind = Ada_Tokenizer.Procedure_T then
        Procedure_Count := Procedure_Count + 1;  -- procedure was found
        Ada_Tokenizer.Get_Token (Kind, Value, Line); -- get identifier
        Ada.Text_IO.Put_Line ("Procedure "
          & Ada.Strings.Unbounded.To_String (Value)
          & " found at line" & Integer'Image (Line));
      end if;
    end loop;
    Ada_Tokenizer.Close_Input;
    Ada.Text_IO.New_Line;
    Ada.Text_IO.Put_Line ("There are" & Integer'Image (Procedure_Count)
      & " procedures in file " & Filename(1..Last));
  else
    Ada.Text_IO.Put_Line ("File not found");
  end if;
end Procedure_Count;




